package com.itheima.service.impl;

import com.itheima.dao.ActReModelDao;
import com.itheima.pojo.ActReModel;
import com.itheima.service.ActReModelService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (ActReModel)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:50
 */
@Service("actReModelService")
public class ActReModelServiceImpl implements ActReModelService {
    @Resource
    private ActReModelDao actReModelDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id_ 主键
     * @return 实例对象
     */
    @Override
    public ActReModel queryById(String id_) {
        return this.actReModelDao.queryById(id_);
    }

    /**
     * 分页查询
     *
     * @param actReModel 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ActReModel> queryByPage(ActReModel actReModel, PageRequest pageRequest) {
        long total = this.actReModelDao.count(actReModel);
        return new PageImpl<>(this.actReModelDao.queryAllByLimit(actReModel, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param actReModel 实例对象
     * @return 实例对象
     */
    @Override
    public ActReModel insert(ActReModel actReModel) {
        this.actReModelDao.insert(actReModel);
        return actReModel;
    }

    /**
     * 修改数据
     *
     * @param actReModel 实例对象
     * @return 实例对象
     */
    @Override
    public ActReModel update(ActReModel actReModel) {
        this.actReModelDao.update(actReModel);
        return this.queryById(actReModel.getId_());
    }

    /**
     * 通过主键删除数据
     *
     * @param id_ 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id_) {
        return this.actReModelDao.deleteById(id_) > 0;
    }
}
